#ifndef BOYAA_DBPART_H_20090707
#define BOYAA_DBPART_H_20090707

#include <global.h>
#include <map>
#include <vector>
#include "def.h"
#include "baseDbPart.h"
#include "Singleton.h"
#include "3400_api_order.pb.h"


class CDbPart
{
public:
	CDbPart();
	virtual ~CDbPart();

public:
    static CDbPart* Instance()
	{
		return CSingleton<CDbPart>::Instance();
	}

public:
	std::string GetDayDateString(time_t now, std::string delimiter = "_", int64 uid = -1);
	std::string GetCurDayDateString(std::string delimiter = "_", int64 uid = -1);

protected:
	bool MysqlTabelExist(const std::string& tabel);

public:
	bool CreateApiOrderException(const api_order::ApiOrder& api_order);
	bool BatchCreateApiOrderException(const std::vector<api_order::ApiOrder>& api_order_group);
	bool FinishApiOrderException(const api_order::ApiOrder& api_order, std::int32_t flag, std::int32_t trade_time = 0);

	bool createApiOrderExceptionTable(const std::string& tabel);
	bool addApiOrderException(const std::string& tabel, const api_order::ApiOrder& api_order);
	bool finishApiOrderException(const std::string& tabel, const api_order::ApiOrder& api_order, std::int32_t flag);
protected:
	void CreateApiOrderExceptionTabel(const std::string& tabel);
	bool CheckApiOrderExceptionTabel(const std::string& tabel, bool just_check = false);
	bool FinishApiOrderExceptionByTime(const api_order::ApiOrder& api_order, std::int32_t flag, std::int32_t trade_time = 0);

protected:
	std::string EscapeString(const std::string& input);
public:
	CBaseDbPart* m_dbHandler;
};
#endif
